package com.ken.springcloud.config;

import com.ken.springcloud.anno.RemarkInfo;
import com.ken.springcloud.enums.UsedComponent;
import com.ken.myRule.MyRandomRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * <ul>
 * <li>Title: MyConfiguration</li>
 * <li>Description: TODO </li>
 * </ul>
 *
 * @author swc
 * @date 2021-08-26 11:45
 */
@RemarkInfo(usedComponent = {UsedComponent.Ribbon},remark = "RibbonClient注解的name为服务提供者的application.name ")
@Configuration
public class MyConfiguration  {

    //IRule  ribbon 提供的实现负载均衡的接口
    // RoundRobinRule  轮询算法规则
    //RandomRule  随机算法规则  其他 通过IRule 去看就行了
    @Bean
    @LoadBalanced //提供负载均衡 ribbon
    public RestTemplate createRestTemplate(){
        return new RestTemplate();
    }

   /* @RemarkInfo(usedComponent = {UsedComponent.Ribbon},remark = "自定义负载均衡 需要把这块注掉 请找到KenRule")
    @Bean
   public IRule myRule(){
       return new RandomRule();//实现的是随机算法
   }*/

}
